package com.network.topo.snmp;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.snmp4j.Target;

import com.network.util.snmp4j.SnmpGet;
import com.network.util.snmp4j.SnmpGetResultSet;

public class Dot1dBasePortTable extends AbstractXxxTable
{
	private static ArrayList<String> oidList = null;
	private HashMap<Object, RowData> objDataMap = new HashMap<Object, RowData>();
	private HashMap<Object, RowData> indexDataMap = new HashMap<Object, RowData>();
	private int rowCount = 0;

	private Dot1dBasePortTable(SnmpGetResultSet resultSet)
	{
		this.resultSet = resultSet;
		if (this.resultSet != null)
		{
			rowCount = this.resultSet.getRowCount();
			for (int i = 0; i < rowCount; i++)
			{
				RowData rowData = new RowData();
				int oidIndex = 0;
				rowData.dot1dBasePort = getValue(getOidList().get(oidIndex++), i);
				rowData.dot1dBasePortIfIndex = getValue(getOidList().get(oidIndex++), i);
				indexDataMap.put(i, rowData);
				objDataMap.put(rowData.getDot1dBasePort(), rowData);
			}
		}
	}

	
	//wang shuang jian
//	public static Dot1dBasePortTable getInstance(SnmpGet snmpGet, Target target)
//	{
//		SnmpGetResultSet sgrs = null;
//		Dot1dBasePortTable instance = null;
//		try
//		{
//			sgrs = snmpGet.query(getOidList(), target);
//		}
//		catch (IOException e)
//		{
//			e.printStackTrace();
//		}
//		if (sgrs != null && sgrs.next() == true)
//		{
//			instance = new Dot1dBasePortTable(sgrs);
//		}
//		return instance;
//	}
	
	public static Dot1dBasePortTable getInstance(SnmpGet snmpGet, Target target, List<String> commList)
	{
		SnmpGetResultSet sgrs = null;
		Dot1dBasePortTable instance = null;
		try
		{
			sgrs = snmpGet.query(getOidList(), target, commList);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		if (sgrs != null && sgrs.next() == true)
		{
			instance = new Dot1dBasePortTable(sgrs);
		}
		return instance;
	}

	public static synchronized ArrayList<String> getOidList()
	{
		if (oidList == null)
		{
			oidList = new ArrayList<String>();
			oidList.add("1.3.6.1.2.1.17.1.4.1.1");
			oidList.add("1.3.6.1.2.1.17.1.4.1.2");
		}
		return oidList;
	}
	public class RowData
	{
		private String dot1dBasePort = "";
		private String dot1dBasePortIfIndex = "";

		public String getDot1dBasePort()
		{
			return dot1dBasePort;
		}

		public void setDot1dBasePort(String dot1dBasePort)
		{
			this.dot1dBasePort = dot1dBasePort;
		}

		public String getDot1dBasePortIfIndex()
		{
			return dot1dBasePortIfIndex;
		}

		public void setDot1dBasePortIfIndex(String dot1dBasePortIfIndex)
		{
			this.dot1dBasePortIfIndex = dot1dBasePortIfIndex;
		}
	}

	public String getDot1dBasePort(Object obj, boolean useIndex)
	{
		String rtnValue = "";
		RowData rowData = null;
		if (useIndex)
		{
			rowData = indexDataMap.get(obj);
		}
		else
		{
			rowData = objDataMap.get(obj);
		}
		if (rowData != null)
		{
			rtnValue = rowData.getDot1dBasePort();
		}
		return rtnValue;
	}

	public String getDot1dBasePortIfIndex(Object obj, boolean useIndex)
	{
		String rtnValue = "";
		RowData rowData = null;
		if (useIndex)
		{
			rowData = indexDataMap.get(obj);
		}
		else
		{
			rowData = objDataMap.get(obj);
		}
		if (rowData != null)
		{
			rtnValue = rowData.getDot1dBasePortIfIndex();
		}
		return rtnValue;
	}
}
